package leetcode.editor.cn;

import java.util.HashMap;
import java.util.Map;

//Java：两数之和
public class TwoSum{
    public static void main(String[] args) {
        Solution solution = new TwoSum().new Solution();
        // TO TEST
    }
    //leetcode submit region begin(Prohibit modification and deletion)
    class Solution {
        public int[] twoSum(int[] nums, int target) {
            if (nums.length == 0) return null;
            Map<Integer, Integer> tempMap = new HashMap<>();
            for (int i = 0; i < nums.length; i++) {
                if (tempMap.containsKey(target - nums[i])) {
                    return new int[]{tempMap.get(target - nums[i]), i};
                } else {
                    tempMap.put(nums[i], i);
                }
            }
            return null;
        }
    }
//leetcode submit region end(Prohibit modification and deletion)

}